Various mechanisms exist for context switching between processes controlled by an operating system. Similarly, in virtualization environments, context switching is necessary when the virtual machine (VM) scheduler, typically a virtual machine monitor/manager (VMM) switches between active and inactive virtual machines. In a virtualization environment, the VMM schedules the available processor cycles among running operating systems. The various operating systems (OSs) run in corresponding guest virtual machines. Before scheduling a guest VM to run, the context of the currently running VM must be saved to ensure that it will run properly when it is scheduled to run again.
Various processor registers must be saved as part of the context switch. Standard registers, stack pointers, MMX, single instruction multiple data (SIMD) and floating point (FP) registers must be saved, in addition to any processor-specific registers. When context is switched from the currently running VM, a context save is performed before the next scheduled VM is scheduled. Context registers for the next scheduled VM are restored prior to allowing the VM to run again. Context switching can be expensive in terms of time, power and other resources.